﻿#ifndef WIDGET_H
#define WIDGET_H

#define UI_RESIZE_AUTO 1
#define UI_RESIZE_POS_FIX 2
#define UI_RESIZE_SIZE_FIX 3
#define UI_RESIZE_ALL_FIX 4
#define UI_RESIZE_POS_FIX_H_FIX 5
#define UI_RESIZE_POS_FIX_W_FIX 6
#define UI_RESIZE_POS_FIX_W_FIX_HSUB_PAD 7      /*位置固定不变，宽度不变，高度按差值填充--可能仅适用于两个控件间，一个高度固定，另外填充所有*/
#define UI_RESIZE_POS_FIX_H_FIX_WSUB_PAD 8      /*位置固定不变，高度不变，宽度按差值填充--可能仅适用于两个控件间，一个宽度固定，另外填充所有*/
#define UI_RESIZE_POS_FIX_Y_REVFIX_X_FIX_HSUB_PAD 10      /*位置固定Y，反向固定X,，宽度不变，高度按差值填充--可能仅适用于两个控件间，一个高度固定，另外填充所有*/
#define UI_RESIZE_POS_FIX_Y_REVFIX_X_FIX_SIZE_FIX 11      /*位置固定Y，反向固定X,尺寸不变*/
#define UI_RESIZE_POS_FIX_Y_REVFIX_X_AUTO_SIZE_AUTO 12      /*位置固定Y，反向自动X,尺寸自动变化*/
#define UI_RESIZE_CENTER_SIZE_FIX 21                     /*水平&&垂直居中，尺寸不变*/
#define UI_RESIZE_POS_FIX_SIZE_CURRENT 20
#include <QWidget>
#include <QString>
#include <QPainter>
#include <QDebug>
#include "Label.h"
#include "Combobox.h"
#include "LineEdit.h"
#include "PushButton.h"
#include "ResizeBase.h"
#include "ui_base_lib_global.h"
#include "ui_base_lib.h"
class UI_BASE_LIBSHARED_EXPORT Widget : public QWidget,public ResizeBase
{
    Q_OBJECT
public:
    explicit Widget(QWidget *parent = nullptr,QString name = "");

    void addResizeBaseObj(Widget *p);
    void addResizeBaseObj(Label *p);
    void addResizeBaseObj(PushButton *p);
    void addResizeBaseObj(Combobox *p);
        void addResizeBaseObj(LineEdit *p);

    void removeResizeBaseObj(Widget *p);
    void removeResizeBaseObj(Label *p);
    void removeResizeBaseObj(PushButton *p);
    void removeResizeBaseObj(Combobox *p);

    void removeResizeBaseObj(LineEdit *p);

    //    /*设置是否跟随变化*/
    //    void setAutoResize(int flag);
    //    int getAutoResize();


    void paintEvent(QPaintEvent* e);

    void initStyleSheet(QString sytle);
    virtual void resizeEvent(QResizeEvent *event);
    virtual void resetLayout();



    void mRecalcOrginSize();

    void startResize(QWidget* pQWidget, ResizeBase* pResizeBase, int flag);

protected:
    bool m_bOnAutoResize;
    QString m_name;

    QList<Widget*> m_listResizeBase;
    QList<Label*> m_listResizeBaseLabel;
    QList<PushButton*> m_listResizeBaseButton;
    QList<Combobox*> m_listResizeBaseCombox;
        QList<LineEdit*> m_listResizeBaseLineEdit;
public:
    void mCalcRectByStrech(QRect * rectOrigin, double fXPercent, double fYPercent, double fWidthPercent, double fHeightPercent);
signals:
    /*HTTP POST N的传输接口，异步调用*/
    void evt_PostHttpMsg(QObject* requestObj);

    /*HTTP POST N的传输接口，同步调用*/
    int evt_PostHttpMsgSync(QObject* requestObj);

    void evt_dataChanged(void* data);

    void evt_systemFunc(void* data , bool isEmit);
public slots:

    /*接收HTTP数据结果*/
    virtual void on_RecvHttpMsg(void* requestObj);

};
class RadioUSerData : public QObjectUserData
{
public:
    double m_fX;
    double m_fY;
    double m_fWidth;
    double m_fHeight;
    QFont  m_fontOrgin;
    int    m_nPixelFont;
    QSize  m_sizeOrgin;
};
#endif 
